package gui.specialGUIs;

import gui.designComponents.TMTDefaultFormBuilder;
import gui.designComponents.TMTNormalButton;
import gui.designComponents.TMTPanel;
import gui.designComponents.TMTPasswordField;
import gui.designComponents.TMTTextField;

import java.util.ResourceBundle;

import javax.swing.JLabel;

import app.Controller;
import app.Model;
import bundles.BundleLoader;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;

import definitions.Commands;

/**
 * Login Panel
 * 
 * @author MK
 * 
 */
public class LoginPanel extends TMTPanel {

	private TMTNormalButton loginButton;
	private TMTTextField userNameField;
	private TMTPasswordField passwordField;

	public LoginPanel(Model model, Controller centralController) {

		ResourceBundle resBundle = BundleLoader.getResourceBundle();

		userNameField = new TMTTextField();
		passwordField = new TMTPasswordField();

		loginButton = new TMTNormalButton("Login");
		loginButton.setActionCommand(Commands.DO_LOGIN);
		loginButton.addActionListener(centralController);

		FormLayout layout = new FormLayout(
				"right:max(60dlu;p), 7dlu, 80dlu, 7dlu, " 
				+ "");

		DefaultFormBuilder builder = TMTDefaultFormBuilder.getDFB(layout);

		builder.append("", new JLabel());
		builder.nextLine();
		builder.append(resBundle.getString("accountName"), userNameField);
		builder.nextLine();
		builder.append(resBundle.getString("accountPassword"), passwordField);
		builder.nextLine();
		builder.append("", loginButton);
		builder.nextLine();
		builder.append("", new JLabel());

		add(builder.getPanel());
	}

	public void update() {
		userNameField.setText("");
		passwordField.setText("");
	}

	public TMTTextField getUserNameField() {
		return userNameField;
	}

	public TMTPasswordField getPasswordField() {
		return passwordField;
	}
}